/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "service_instance")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ServiceInstance.findAll", query = "SELECT s FROM ServiceInstance s"),
    @NamedQuery(name = "ServiceInstance.findById", query = "SELECT s FROM ServiceInstance s WHERE s.id = :id"),
    @NamedQuery(name = "ServiceInstance.findByIp", query = "SELECT s FROM ServiceInstance s WHERE s.ip = :ip"),
    @NamedQuery(name = "ServiceInstance.findByUrl", query = "SELECT s FROM ServiceInstance s WHERE s.url = :url")})
public class ServiceInstance implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @Column(name = "IP")
    private String ip;
    @Column(name = "URL")
    private String url;
    @JoinColumn(name = "Id_VMInstance", referencedColumnName = "ID")
    @ManyToOne
    private VirtualMachineInst idVMInstance;
    @JoinColumn(name = "Id_Service", referencedColumnName = "ID")
    @ManyToOne
    private Service idService;
    @JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Component component;

    public ServiceInstance() {
    }

    public ServiceInstance(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public VirtualMachineInst getIdVMInstance() {
        return idVMInstance;
    }

    public void setIdVMInstance(VirtualMachineInst idVMInstance) {
        this.idVMInstance = idVMInstance;
    }

    public Service getIdService() {
        return idService;
    }

    public void setIdService(Service idService) {
        this.idService = idService;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ServiceInstance)) {
            return false;
        }
        ServiceInstance other = (ServiceInstance) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.ServiceInstance[ id=" + id + " ]";
    }
    
}
